<?php

namespace app\admin\model;

use think\Model;


class DoctorsDiagnosisLog extends Model
{

    

    

    // 表名
    protected $name = 'doctors_diagnosis_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'starTime_text',
        'endTime_text',
        'is_check_text',
        'type_text'
    ];
    

    
    public function getIsCheckList()
    {
        return ['1' => __('Is_check 1'), '0' => __('Is_check 0')];
    }

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2')];
    }


    public function getStartimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['starTime']) ? $data['starTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getEndtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['endTime']) ? $data['endTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIsCheckTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_check']) ? $data['is_check'] : '');
        $list = $this->getIsCheckList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setStartimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setEndtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function doctors()
    {
        return $this->belongsTo('Doctors', 'doctors_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
